<?php

namespace builder\test\controllers;

use builder\base\BaseController;
use builder\form\FormBuilder;
use builder\form_step\FormStepBuilder;
use builder\form_step\util\fssr\Modal;
use builder\form_step\util\step\Item;
use builder\widget\ajax\Accordion;
use builder\widget\ajax\ButtonDropdown;
use builder\widget\ajax\Carousel;
use builder\widget\WidgetFacade;

//分步表单
class FormStepController extends BaseController
{
    public $publicActions = ['index'];
    public $actionVerbs = ['index' => ['GET', 'POST']];

    //示例
    public function actionIndex()
    {
        if ($this->isPost) {
            return $this->asOk('SUCCESS');
        } else {
            $formStepBuilder = FormStepBuilder::instance(['id' => 'FormStep_Index']);

            $formStepBuilder->setTitle('分步表单')
                ->setPartial(!!@$this->get['_partial'])
                ->setStepItem(function (Item $item) {
                    return $item->title('基本配置')->content(function (FormBuilder $formBuilder) {
                        return $formBuilder->setRequiredStyle()->setFormControl([
                            'a' => $this->formControl->text()->label('用户名')->required(),
                            'a1' => $this->formControl->text()->label('密码')->required(),
                            'a2' => $this->formControl->text()->label('SEO')->required(),
                            'a3' => $this->formControl->text()->label('分类')->required(),
                            'a4' => $this->formControl->text()->label('状态')->required(),
                        ]);
                    });
                })
                ->setStepItem(function (Item $item) {
                    return $item->title('会员配置')->content(function (FormBuilder $formBuilder) {
                        return $formBuilder->setRequiredStyle()->setFormControl([
                            'b' => $this->formControl->text()->label('名称')->required(),
                            'b1' => $this->formControl->text()->label('性别')->required(),
                            'b2' => $this->formControl->text()->label('积分')->required(),
                            'b3' => $this->formControl->text()->label('代码')->required(),
                            'b4' => $this->formControl->text()->label('代理商')->required(),
                            'b5' => $this->formControl->text()->label('登录日期')->required(),
                        ]);
                    });
                })
                ->setStepItem(function (Item $item) {
                    return $item->title('完成')->content(function (FormBuilder $formBuilder) {
                        return $formBuilder->setRequiredStyle()->setFormControl([
                            'c' => $this->formControl->text()->label('内容')->required(),
                            'c1' => $this->formControl->text()->label('理由')->required(),
                            'c2' => $this->formControl->text()->label('解决')->required(),
                            'c3' => $this->formControl->text()->label('爱好')->required(),
                        ]);
                    });
                })
                ->setSubmitBtn()
                ->setBackBtn()
                ->setExtraBtn([
                    WidgetFacade::echo2Return(function () {
                        \yii\bootstrap4\Modal::$autoIdPrefix = 'ModalB4';
                        \yii\bootstrap4\Modal::begin([
                            'title' => 'ModalB4 title',
                            'bodyOptions' => [
                                'class' => 'text-center',
                            ],
                            'toggleButton' => [
                                'label' => 'ModalB4 btn',
                                'class' => 'layui-btn layui-btn-sm layui-btn-primary',
                            ],
                        ]);
                        echo implode("\n", array_fill(0, 100, 'ModalB4 content'));
                        \yii\bootstrap4\Modal::end();
                    }),
                ])
//                ->setExtraBtn([
//                    WidgetFacade::echo2Return(function () {
//                        echo ButtonDropdown::widget([
//                            'label' => 'Action',
//                            'dropdown' => [
//                                'items' => [
//                                    ['label' => 'DropdownA', 'url' => '/'],
//                                    ['label' => 'DropdownB', 'url' => '#'],
//                                ],
//                            ],
//                        ]);
//
//                    }),
//                ])
//                ->setExtraBtn([
//                    Accordion::widget([
//                        'options' => [
//                            'id' => 'wwwwww',
//                        ],
//                        'items' => [
//                            [
//                                'label' => 'Collapsible Group Item #1',
//                                'content' => 'Anim pariatur cliche...',
//                                'contentOptions' => ['class' => 'in']
//                            ]
//                        ],
//                    ]),
//                ])
//                ->setExtraBtn([
//                    WidgetFacade::echo2Return(function () {
//                        \builder\widget\ajax\Modal::begin([
//                            'id' => 'eeeeeeeeeeeeeeeeeeee',
//                            'title' => 'ModalB4 title',
//                            'bodyOptions' => [
//                                'class' => 'text-center',
//                            ],
//                            'toggleButton' => [
//                                'label' => 'ModalB4 btn',
//                                'class' => 'layui-btn layui-btn-sm layui-btn-primary',
//                            ],
//                        ]);
//                        echo implode("\n", array_fill(0, 100, 'ModalB4 content'));
//                        \builder\widget\ajax\Modal::end();
//                    }),
//                ])
//                ->setExtraBtn([
//                    Carousel::widget([
//                        'id' => 'FFFFFFFFFFFFFFFFFFFFFFFFF',
//                        'options' => [
//                            'ym2-image-group' => '',
//                            'style' => 'width:100px;height:100px;',
//                        ],
//                        //'controls' => false,
//                        'items' => [
//                            [
//                                'content' => '<img ym2-full-image style="width:100px;height:100px;" src="https://buerzz.damanzj.com/upload/image/goods_manager/G20230720164108385/album_images/202306291606534csyPMlILJ.jpg"/>',
//                            ],
//                            [
//                                'content' => '<img ym2-full-image style="width:100px;height:100px;" src="https://buerzz.damanzj.com/upload/image/goods_manager/G20230720164108385/album_images/20230402153138IlzZxeOSV1.jpg"/>',
//                            ],
//                            [
//                                'content' => '<img ym2-full-image style="width:100px;height:100px;" src="https://buerzz.damanzj.com/upload/image/goods_comment/14219/6718/20230720145807HmPqj8T2R5.png"/>',
//                            ],
//                        ],
//                    ]),
//                ])
                ->setSubmitConfirm()
                ->setFssRedirect(function (Modal $modal) {
                    return $modal->title('测试');
                })
                ->setRootLayout([
                    'class' => ['col-md-8 offset-md-2']
                ]);

            return $formStepBuilder->render();
        }
    }
}